//
// Created by xili on 2024/8/28 18:53.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int minDeletion(vector<int> &nums) {
        int ans = 0;
        int n = nums.size();
        stack<int> s;
        for (int i = 0; i < n; i++) {
            if (!s.empty() && (i - ans) % 2 == 1 && nums[i] == s.top()) {
                ans++;
                continue;
            }
            s.push(nums[i]);
        }
        return s.size() & 1 ? ans + 1 : ans;
    }
};